﻿using FolderTag.Model;

namespace FolderTag.DB.Dbo
{
    [SQLBuilder.Core.Attributes.Table("folder_tag")]
    public class FolderTagDbo
    {
        /// <summary>
        /// 默认构造
        /// </summary>
        public FolderTagDbo()
        {
            Color = "255,128,128,128";
        }

        /// <summary>
        /// 添加构造
        /// </summary>
        public FolderTagDbo(string tagName) : this()
        {
            Name = tagName;
        }

        /// <summary>
        /// 编号
        /// </summary>
        [SQLBuilder.Core.Attributes.Key]
        public int? Id { get; set; }

        /// <summary>
        /// 标签名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 标签颜色
        /// </summary>
        public string Color { get; set; }

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static FolderTagDbo Create(TagItem tagItem)
        {
            FolderTagDbo result = new FolderTagDbo()
            {
                Id = tagItem.Id,
                Name = tagItem.Name,
            };
            result.Color = $"{tagItem.Color.A},{tagItem.Color.R},{tagItem.Color.G},{tagItem.Color.B}";
            return result;
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static FolderTagDbo CreateNew(TagItem tagItem)
        {
            FolderTagDbo result = Create(tagItem);
            result.Id = null;
            return result;
        }
    }
}
